package org.tea.inventory.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tea.inventory.dao.tea.CustomerSmallMapper;
import org.tea.inventory.domain.sys.UserInfo;
import org.tea.inventory.domain.tea.CustomerSmall;
import org.tea.inventory.service.ICustomerGuestService;
import org.tea.inventory.utils.UserUtil;

import java.util.Date;
import java.util.List;

/**
 * 散客管理信息Service业务层处理
 * 
 * @author dongxb
 * @date 2025-04-27
 */
@Service
public class CustomerGuestlServiceImpl implements ICustomerGuestService
{
    @Autowired
    private CustomerSmallMapper customerSmallMapper;

    /**
     * 查询散客管理信息
     * 
     * @param id 散客管理信息主键
     * @return 散客管理信息
     */
    @Override
    public CustomerSmall selectCustomerSmallById(Long id)
    {
        return customerSmallMapper.selectCustomerSmallById(id);
    }

    /**
     * 查询散客管理信息列表
     * 
     * @param customerSmall 散客管理信息
     * @return 散客管理信息
     */
    @Override
    public List<CustomerSmall> selectCustomerSmallList(CustomerSmall customerSmall)
    {
        //只查询未删除的信息
        customerSmall.setDelFlag(0);
        //类型2为散客
        customerSmall.setCustomerType("2");
        List<CustomerSmall> customerSmalls = customerSmallMapper.selectCustomerSmallList(customerSmall);
        customerSmalls.stream().forEach(bean -> {
            bean.setSexStr("0".equals(bean.getSex()) ? "男" : "女");
        });
        return customerSmalls;
    }

    /**
     * 新增散客管理信息
     * 
     * @param customerSmall 散客管理信息
     * @return 结果
     */
    @Override
    public int insertCustomerSmall(CustomerSmall customerSmall)
    {
        Date date = new Date();
        UserInfo user = UserUtil.getUser();
        //客户类型为2 散客
        customerSmall.setCustomerType("2");
        customerSmall.setCreateDate(date);
        customerSmall.setCreateUserId(user.getLoginId());
        return customerSmallMapper.insertCustomerSmall(customerSmall);
    }

    /**
     * 修改散客管理信息
     * 
     * @param customerSmall 散客管理信息
     * @return 结果
     */
    @Override
    public int updateCustomerSmall(CustomerSmall customerSmall)
    {
        Date date = new Date();
        UserInfo user = UserUtil.getUser();
        customerSmall.setUpdateDate(date);
        customerSmall.setUpdateUserId(user.getLoginId());
        return customerSmallMapper.updateCustomerSmall(customerSmall);
    }

    /**
     * 批量删除散客管理信息
     * 
     * @param ids 需要删除的散客管理信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerSmallByIds(Long[] ids)
    {
        for (Long id : ids) {
            CustomerSmall customerSmall = new CustomerSmall();
            customerSmall.setId(id);
            customerSmall.setDelFlag(1);
            customerSmallMapper.updateCustomerSmall(customerSmall);
        }
        return ids.length;
    }

    /**
     * 删除散客管理信息信息
     * 
     * @param id 散客管理信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerSmallById(Long id)
    {
        CustomerSmall customerSmall = new CustomerSmall();
        customerSmall.setId(id);
        customerSmall.setDelFlag(1);
        return customerSmallMapper.updateCustomerSmall(customerSmall);
    }

    @Override
    public List<CustomerSmall> selectCustomerSmallByCodeOrName(CustomerSmall customerSmall) {
        //类型2为散客
        customerSmall.setCustomerType("2");
        return customerSmallMapper.selectCustomerSmallByCodeOrName(customerSmall);
    }
}
